#include "dtalbum.h"
#include "../database/dbalbum.h"
#include <QStringList>

DtAlbum::DtAlbum()

{
    id = -1;
    name = "";
    cover = "";
}

DtAlbum::DtAlbum(const QString & name, const int year, const int id,
                 const QString & covers, const bool heart)
{
    this->id = id;
    this->name = name;
    this->cover = covers;
    this->year = year;
    this->heart.setHeart(heart);
}

DtAlbum::DtAlbum(const DtAlbum &album)
{
    id = album.id;
    name = album.name;
    cover = album.cover;
    year = album.year;
    heart.setHeart(album.heart.isHeart());
    lArtist = album.lArtist;
    lGenre = album.lGenre;
    lTrack = album.lTrack;
}

DtAlbum::~DtAlbum()
{

}

QDebug operator<<(QDebug dbg, const DtAlbum &album)
{
    dbg.space() << "Album" << album.getId() << album.getName()
                << album.getYear() << album.getCovers();
    return dbg.space();
}

void DtAlbum::clicked(const int section)
{
    switch (section) {
    case DtAlbum::Play: /* Play */
        playSvg.setPlay(!playSvg.isPlay());
        break;
    case DtAlbum::Add: /* Ajouter */
        break;
    case DtAlbum::Name: /* Titre de l'album */
        break;
    case DtAlbum::Year: /* Année */
        break;
    case DtAlbum::Heart: /* Heart */
        heart.setHeart(!heart.isHeart());
        DbAlbum::setHeart(*this);
        break;
    default:
        break;
    }
}

DtAlbum * DtAlbum::findById(QList<DtAlbum> &lAlbum, const int id)
{
    for(QList<DtAlbum>::Iterator it = lAlbum.begin();
        it != lAlbum.end(); it++)
    {
        if((*it).getId() == id)
            return &(*it);
    }
    return NULL;
}

QString DtAlbum::getCovers() const
{
    return cover;
}

void DtAlbum::setCovers(const QString & covers)
{
    this->cover = covers;
}

int DtAlbum::getYear() const
{
    return year;
}

void DtAlbum::setYear(const int year)
{
    this->year = year;
}

void DtAlbum::addTrack(DtTrack *track)
{
    if(!lTrack.contains(track))
    {
        lTrack.append(track);
    }
}

QList<DtTrack *> &DtAlbum::getTracks()
{
    return lTrack;
}

QList<DtArtist *> &DtAlbum::getArtists()
{
    return lArtist;
}

QList<DtGenre *> &DtAlbum::getGenres()
{
    return lGenre;
}

void DtAlbum::addGenre(DtGenre *genre)
{
    if(!lGenre.contains(genre))
        lGenre.append(genre);
}

void DtAlbum::addArtist(DtArtist *artist)
{
    if(!lArtist.contains(artist))
        lArtist.append(artist);
}
